package com.hardydou.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class RabbitUtil {

    private static String username = "guest";
    private static String password = "guest";
    private static String virtualHost = "";
    private static String host = "192.168.4.230";
    private static int portNumber = 5672;
    private static ConnectionFactory factory = null;

    static {
        factory = new ConnectionFactory();
        factory.setUsername(username);
        factory.setPassword(password);
//        factory.setVirtualHost(virtualHost);
        factory.setHost(host);
        factory.setPort(portNumber);
    }


    public static Channel getChannel() {
        try {
            return getConnection().createChannel();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Connection getConnection() {
        try {
            return factory.newConnection();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


}
